home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / NCSA / tn3270 2.3d26 source / tn3270 / writescr.c < prev    next >
Text File  |  1991-05-23  |  35KB  |  1,532 lines

  1. /*
  2.  *  tn3270 for the Macintosh Source Code
  3.  *  Brown University Computing and Information Services
  4.  *  Version 2.3d21, January 17, 1991
  5.  *  Copyright (c) 1988, 1989, 1990, 1991 by Brown University and by
  6.  *  Peter John DiCamillo.
  7.  *
  8.  *  Permission is granted to any individual or institution to use, copy,
  9.  *  or redistribute the binary version of this software and its
  10.  *  documentation provided this notice and the copyright notices are
  11.  *  retained.  Permission is granted to any individual or non-profit
  12.  *  institution to use, copy, modify, or redistribute the source files
  13.  *  of this software provided this notice and the copyright notices are
  14.  *  retained.  This software may not be distributed for profit, either
  15.  *  in original form or in derivative works, nor can the source be
  16.  *  distributed to other than an individual or a non-profit institution.
  17.  *  Any  individual or group interested in seeing and/or using these
  18.  *  source files but who are prevented from doing so by the above
  19.  *  constraints should contact Don Wolfe, Assistant Vice-President for
  20.  *  Computer Systems at Brown University, (401) 863-7250, for possible
  21.  *  software licensing of the source developed at Brown.
  22.  *
  23.  *  Brown University and Peter John DiCamillo make no representations
  24.  *  about the suitability of this software for any purpose.
  25.  *
  26.  *  BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
  27.  *  EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
  28.  *  INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
  29.  *  WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
  30.  *
  31.  */
  32.  
  33. #define __SEG__ 3270seg1
  34.  
  35. #include "maclib.h"
  36. #include "termdef.h"
  37. #include "globals.h"
  38. #include "palette.h"
  39.  
  40. long GetA5();
  41.  
  42. extern char vmxbgn, vmxsub;
  43. extern Rect statRect, textRect, cposRect;
  44. extern short hpixsize, vpixsize, saveoff;
  45. extern short htxtstrt, vtxtstrt, vtxtsize, htxtsize, curvsize, curhsize;
  46. extern short scrhoff, scrhsize;
  47. extern short x_origin, y_origin;
  48. extern short maxoff, maxcnt;
  49. extern PaletteHandle myPalette;
  50. extern char colorfield;
  51. extern RGBColor realblack, realwhite;
  52. extern DialogPtr xdlgptr;
  53. extern unsigned char cutflag;
  54. extern unsigned char nlbuff[];
  55. extern char statcpos;    /* if true, only draw cursor position */
  56.  
  57. Rect gr_rect;            /* grow icon rectangle */
  58. selcoord lastsel;        /* points for last text selection */
  59. static char framedfield;    /* screen contains framed fields */
  60.  
  61. invldscr()
  62. {
  63. register short rc;
  64. GrafPtr gp;
  65.  
  66. if (sw_bgrnd) {
  67.     sw_upd = 1;
  68.     return;
  69.     }
  70. if (pndinv) return;
  71. GetPort(&gp);
  72. rc = 0;
  73. if (!(serflg || tcpflg)) {
  74.     SetPort(WritePtr);
  75.     if (textmap) {
  76.         setgdev();
  77.         rc = writescr(0);
  78.         resetgdev();
  79.         }
  80.     }
  81. else needwrite = 1;
  82. SetPort(myWindow);
  83. if (rc == 0) InvalRect(&textRect);
  84. SetPort(gp);
  85. checkpos();
  86. }
  87.  
  88. checkpos()
  89. {
  90. GrafPtr gp;
  91.  
  92. if (!cs.curpos) return;
  93. statcpos = 1;
  94. newstat();
  95. statcpos = 0;
  96. }
  97.  
  98. writescr(printflag)
  99. char printflag;
  100. {
  101. register unsigned short a, i, cattr, fattr, start, count;
  102. unsigned short offset, lastfield;
  103. char geflg, g;
  104. /* char msg[64];        !!!!! */
  105. static unsigned long * Ticks = (unsigned long *)0x16a;
  106. unsigned long stasklim;
  107.  
  108. /* if (cs.dblevel == 2) ticktime = (*Ticks);        !!!!! */
  109.  
  110. /* get field attribute for first screen position, even if it */
  111. /* is defined by a subsequent field wrapping to the start.   */
  112. fattr = lastfield = 0;
  113. if (fmtscrn) {
  114.     if (atrbuff[0] & 0x8000) {
  115.         lastfield = atrbuff[0] & 0x3fdf;
  116.         fattr = lastfield & 0x3f1f;
  117.         }
  118.     else for (i = maxoff; i > 0; i--)
  119.         if (atrbuff[i] & 0x8000) {
  120.             lastfield = atrbuff[i] & 0x3fdf;
  121.             fattr = lastfield & 0x3f1f;
  122.             break;
  123.             }
  124.     }
  125.  
  126. WriteCurr = 0;
  127. if (printflag == 0) EraseRect(&textRect);
  128. framedfield = 0;
  129. cattr = fattr;
  130. if (tcpflg) stasklim = (*Ticks) + 4;
  131. for (start = 0; start < maxcnt; start += scrhsize) {
  132.     if (pndinv) return(1);
  133.     if (tcpflg) {
  134.         if ((*Ticks) > stasklim) {
  135.             myStask();
  136.             stasklim = (*Ticks) + 4;
  137.             }
  138.         }
  139.     count = 0;
  140.     geflg = 0;
  141.     offset = start;
  142.     MoveTo(htxtstrt, WriteCurr*vtxtsize + vtxtstrt);
  143.     for (i=0; i < scrhsize; i++) {
  144.         a = atrbuff[start+i];
  145.         g = (a & 0x40c0) != 0;
  146.         a &= 0xbfff;
  147.         if (a & 0x8000) {
  148.             dfield(offset, count, lastfield, cattr, geflg);
  149.             /* attribute byte is a field by itself */
  150.             offset = start + i;
  151.             count = -1;        /* indicates attribute byte */
  152.             fattr = a & 0x3fff;
  153.             dfield(offset, count, fattr, fattr, 0);
  154.             lastfield = fattr & 0x3fdf;    /* selection doesn't propagate */
  155.             fattr = lastfield & 0x3f1f;
  156.             cattr = fattr;
  157.             count = 0;
  158.             geflg = 0;
  159.             offset = start + i + 1;
  160.             }
  161.         else {
  162.             a &= 0x3f3f;
  163.             if ((a == 0) && (cattr == fattr)) {
  164.                 count++;
  165.                 geflg |= g;
  166.                 continue;
  167.                 }
  168.             if (a == cattr) {
  169.                 count++;
  170.                 geflg |= g;
  171.                 continue;
  172.                 }
  173.             /* else start new field */
  174.             dfield(offset, count, lastfield, cattr, geflg);
  175.             count = 1;
  176.             offset = start + i;
  177.             cattr = a;
  178.             geflg = g;
  179.             }
  180.         }
  181.     dfield(offset, count, lastfield, cattr, geflg);
  182.     WriteCurr ++;
  183.     }
  184.  
  185. if (printflag) return(0);
  186. x = curadr%scrhsize;
  187. y = curadr/scrhsize;
  188. defcursor(x, y);        /* define er rectangle for cursor */
  189. if (!textmap) drawcurs(0);
  190.  
  191. /* if (cs.dblevel == 2) {         !!!!!
  192.     ticktime = (*Ticks) - ticktime;
  193.     sprintf(msg, "time for writescr: %ld ticks", ticktime);
  194.     putln(msg);
  195.     }                        */
  196.  
  197. if (pndinv) return(1);
  198. else return(0);
  199. }
  200.  
  201. newcur()
  202. {
  203. GrafPtr gp;
  204.  
  205. if (sw_bgrnd) {
  206.     sw_upd = 1;
  207.     return;
  208.     }
  209. GetPort(&gp);
  210. SetPort(myWindow);
  211. if (textmap) InvalRect(&er);
  212. else drawcurs(1);
  213. x = curadr%scrhsize;
  214. y = curadr/scrhsize;
  215. defcursor(x, y);        /* define er rectangle for cursor */
  216. if (textmap) InvalRect(&er);
  217. else drawcurs(0);
  218. SetPort(gp);
  219. checkpos();
  220. }
  221.  
  222. newchar(offset, value, atr, fattr)
  223. short offset, atr, fattr;
  224. unsigned char value;
  225. {
  226. short newatr, selattr;
  227.  
  228. chrbuff[offset] = value;
  229. if (cutflag) {                /* allow deletion of selection attribute */
  230.     atrbuff[offset] = atr;
  231.     }
  232. else {                        /* preserve selection attribute */
  233.     selattr = atrbuff[offset] & 0x0020;
  234.     atrbuff[offset] = (atr & 0xffdf) | selattr;
  235.     }
  236.  
  237. if (sw_bgrnd) {
  238.     sw_upd = 1;
  239.     return;
  240.     }
  241. newatr = fattr & 0x3fff;
  242. /* if (atr & 0x4000) newatr |= 0x4000; */
  243.  
  244. if (in_len == 0) {
  245.     in_len = 1;
  246.     in_off = offset;
  247.     in_atr = newatr;
  248.     return;
  249.     }
  250.  
  251. if ( (in_atr != newatr) || (in_off/scrhsize != offset/scrhsize) ||
  252.      (offset-in_off-in_len > 0) || (in_off-offset > 1) ) {
  253.         dchar(in_off, in_len, in_atr);
  254.         in_len = 1;
  255.         in_off = offset;
  256.         in_atr = newatr;
  257.         return;
  258.         }
  259.  
  260. in_len++;
  261. if (in_off-offset == 1) in_off--;
  262. }
  263.  
  264. dchar(offset, len, fattr)
  265. short offset, len, fattr;
  266. {
  267. short i, selattr, dstart, dlen;
  268.  
  269. if (len < 1) return;
  270. if (len == 1) {
  271.     seldchar(offset, len, atrbuff[offset] & 0x3f3f, fattr);
  272.     return;
  273.     }
  274. selattr = atrbuff[offset] & 0x3f3f;
  275. dstart = offset;
  276. dlen = 1;
  277. for (i=1; i < len; i++)
  278.     if ((atrbuff[offset+i] & 0x3f3f) != selattr) {
  279.         seldchar(dstart, dlen, selattr, fattr);
  280.         selattr = atrbuff[offset+i] & 0x3f3f;
  281.         dstart = offset+i;
  282.         dlen = 1;
  283.         }
  284.     else dlen++;
  285.     
  286. seldchar(dstart, dlen, selattr, fattr);
  287. }
  288.  
  289. seldchar(offset, len, selattr, fattr)
  290. short offset, len, selattr, fattr;
  291. {
  292. Rect r;
  293. register short x, y;
  294. GrafPtr gp;
  295. unsigned char attrbits;
  296. RGBColor rgbtemp;
  297. short fnum, chrtop;
  298. char prot, fieldfont;
  299.  
  300. prot = (fattr & 0x2000) != 0;
  301. fieldfont = (fattr & 0x00c0) >> 6;
  302. fattr &= 0xff3f;
  303. getdspatr(&attrbits, 0L, &rgbtemp, selattr, fattr);
  304.  
  305. GetPort(&gp);
  306. SetPort(WritePtr);
  307. if (textmap) setgdev();
  308. y = offset/scrhsize;
  309. x = offset%scrhsize;
  310. chrtop = r.top = y*vtxtsize;
  311. if (htxtstrt == 0) r.top--;        /* adjust for 12-point */
  312. r.left = htxtstrt+x*htxtsize;
  313. r.bottom = r.top+vtxtsize;
  314. r.right = r.left + len * htxtsize;
  315. if (!textmap)
  316.     if ((curadr >= offset) && (curadr < offset+len)) drawcurs(1);
  317. if (framedfield) {        /* adjust to not erase any frames on screen */
  318.     r.bottom--;
  319.     }
  320. if (colormac)
  321.     if (attrbits & 0x20) {            /* reversed field */
  322.         RGBBackColor(&rgbtemp);
  323.         if (cs.invertbw) GetEntryColor(myPalette, RGBwhite, &rgbtemp);
  324.                   else GetEntryColor(myPalette, RGBblack, &rgbtemp);
  325.         RGBForeColor(&rgbtemp);
  326.         }
  327.     else RGBForeColor(&rgbtemp);    /* normal field */
  328. EraseRect(&r);
  329. if (!(attrbits & 0x80)) {        /* displayable */
  330.     MoveTo(r.left, vtxtstrt+chrtop);
  331.     txtfield(offset, len, attrbits, prot, fieldfont);
  332.  
  333. /*    if (fattr & 0x4000) fnum = APLFONT;
  334.                    else fnum = stdfont;
  335.     if (attrbits & 0x08) fnum += 2;
  336.     if (fnum != stdfont) TextFont(fnum);
  337.     myDrawText(chrbuff, offset, len, fnum, prot);
  338.     if (fnum != stdfont) TextFont(stdfont); */
  339.  
  340.     if (attrbits & 0x10) {
  341.         MoveTo(r.left, chrtop+vtxtstrt+(curvsize>>2)-3);
  342.         LineTo(r.right+1, chrtop+vtxtstrt+(curvsize>>2)-3);
  343.         }
  344.     if ((!colormac) && (attrbits & 0x20)) InvertRect(&r);
  345.     }
  346. if (colormac && (attrbits & 0x20)) {
  347.     GetEntryColor(myPalette, RGBback, &rgbtemp);
  348.     RGBBackColor(&rgbtemp);
  349.     }
  350. SetPort(myWindow);
  351. if (textmap) {
  352.     resetgdev();
  353.     if (r.top < inrect.top) inrect.top = r.top;
  354.     if (r.left < inrect.left) inrect.left = r.left;
  355.     if (r.bottom > inrect.bottom) inrect.bottom = r.bottom;
  356.     if (r.right > inrect.right) inrect.right = r.right;
  357.     }
  358. else if ((curadr >= offset) && (curadr < offset+len)) drawcurs(0);
  359. SetPort(gp);
  360. }
  361.  
  362. newwrite(upd)
  363. char upd;
  364. {
  365. GrafPtr gp;
  366. BitMap * srcbits;
  367.  
  368. if (sw_bgrnd) return;
  369.  
  370. if (in_len > 0) {
  371.     dchar(in_off, in_len, in_atr);
  372.     in_len = 0;
  373.     }
  374.  
  375. if (!textmap) return;
  376. GetPort(&gp);
  377. SetPort(myWindow);
  378. InvalRect(&inrect);
  379. inrect.top = inrect.left = 32767;
  380. inrect.bottom = inrect.right = -32767;
  381. SetPort(gp);
  382. }
  383.  
  384. dfield(offset, count, fattr, cattr, g)
  385. short offset, count, fattr, cattr;
  386. char g;
  387. {
  388. struct Rect z;
  389. unsigned char attrbits, trim;
  390. short xend, yend, txtcount, txtoff, adjcount, adjoff;
  391. RGBColor rgbfield, rgbrev;
  392. char prot, fieldfont;
  393. short fnum;
  394.  
  395. if (count == 0) return;
  396.  
  397. fieldfont = (fattr & 0x00c0) >> 6;
  398. fattr &= 0xff3f;
  399.  
  400. /* get attribute definition for this field */
  401. prot = (fattr & 0x2000) != 0;
  402. trim = 1;
  403. getdspatr(&attrbits, &trim, &rgbfield, cattr, fattr);
  404. if (count == -1) {
  405.     attrbits = cs.attrmap[6];
  406.     trim = 0;
  407.     count = 1;
  408.     if (cattr & 0x0020) {
  409.         attrbits &= 0x8f;
  410.         attrbits |= 0x20;
  411.         }
  412.     }
  413.  
  414. /* remember where to end up when done */
  415. xend = htxtstrt + (offset%scrhsize)*htxtsize + count*htxtsize;
  416. yend = WriteCurr*vtxtsize + vtxtstrt;
  417.  
  418. /* if appropriate, calculate new count and offset to eliminate leading
  419.    and trailing blanks and nulls  */
  420. adjcount = txtcount = count;
  421. adjoff = txtoff = offset;
  422. calctrim(&txtoff, &txtcount);        /* don't draw blanks and nulls */
  423. if (!(fattr & 0x2000)) trim = 0;    /* unprotected not trimmed */
  424. if (trim) {
  425.     adjcount = txtcount;
  426.     adjoff = txtoff;
  427.     }
  428.  
  429. /* define nominal rectangle for this update */
  430. z.top = WriteCurr * vtxtsize;
  431. z.bottom = z.top + vtxtsize;
  432. if (htxtstrt == 0) {    /* adjust for 12-point */
  433.     z.top--;
  434.     z.bottom--;
  435.     }
  436. z.left = htxtstrt + (adjoff%scrhsize) * htxtsize;
  437. z.right =  z.left + adjcount * htxtsize;
  438.  
  439. /* define colors for normal or reversed field */
  440. if (colormac)
  441.     if (attrbits & 0x20) {
  442.         RGBBackColor(&rgbfield);
  443.         if (adjcount > 0) {
  444.             if (attrbits & 0x40) {
  445.                 z.left -= 1;
  446.                 z.right += 1 - htxtstrt;
  447.                 }
  448.             EraseRect(&z);
  449.             if (attrbits & 0x40) {
  450.                 z.left += 1;
  451.                 z.right -= 1 - htxtstrt;
  452.                 }
  453.             }
  454.         GetEntryColor(myPalette, RGBback, &rgbrev);
  455.         RGBBackColor(&rgbrev);
  456.         if (cs.invertbw) GetEntryColor(myPalette, RGBwhite, &rgbrev);
  457.                   else GetEntryColor(myPalette, RGBblack, &rgbrev);
  458.         RGBForeColor(&rgbrev);
  459.         }
  460.     else RGBForeColor(&rgbfield);
  461.  
  462. /* draw text if not non-display or all blanks or nulls */
  463. if (txtoff != offset) MoveTo(htxtstrt+(txtoff%scrhsize)*htxtsize, yend);
  464. if (!((attrbits & 0x80) || (txtcount == 0)))
  465.     if (g) {
  466.         txtfield(txtoff, txtcount, attrbits, prot, fieldfont);
  467.         }
  468.      else {
  469.         if (fieldfont == 1) fnum = APLFONT;
  470.         else fnum = stdfont;
  471.         if (attrbits & 0x08) fnum += 2;
  472.         if (fnum != stdfont) TextFont(fnum);
  473.          myDrawText(chrbuff, txtoff, txtcount, fnum, prot);
  474.         if (fnum != stdfont) TextFont(stdfont);
  475.         }
  476. MoveTo(xend, yend);
  477.  
  478. /* return if no other attributes */
  479. if (!(attrbits & 0x70)) return;
  480.  
  481. /* return if trimming has removed field */
  482. if (adjcount == 0) return;
  483.  
  484. /* frame if requested */
  485. if (attrbits & 0x40) {
  486.     z.top -= 1;
  487.     z.left -= 2;
  488.     z.right += 2 - htxtstrt; 
  489.     if (colormac) RGBForeColor(&rgbfield);
  490.     FrameRect(&z);
  491.     z.top += 1;
  492.     z.bottom -= 1;
  493.     z.left += 1;
  494.     z.right -= 1;
  495.     framedfield = 1;
  496.     }
  497.  
  498. /* underline if requested */
  499. if (attrbits & 0x10) {
  500.     if (colormac)
  501.         if (attrbits & 0x20) RGBForeColor(&rgbrev);
  502.                         else RGBForeColor(&rgbfield);
  503.     MoveTo(z.left, yend+(curvsize>>2)-3);
  504.     LineTo(z.right-1, yend+(curvsize>>2)-3);
  505.     }
  506.  
  507. /* reverse if requested */
  508. if ((!colormac) && (attrbits & 0x20)) InvertRect(&z);
  509.  
  510. /* leave pen ready for next character */
  511. MoveTo(xend, yend);
  512. }
  513.  
  514. calctrim(offset, count)
  515. short * offset;
  516. short * count;
  517. {
  518. register short adjoff, adjcount, i, j, k;
  519.  
  520. adjcount = j = (*count);
  521. adjoff = k = (*offset);
  522. for (i = 0; i < j; i++) {
  523.     if ((chrbuff[k] == 0x40) || (chrbuff[k] == 0x00)) {
  524.         adjoff++;
  525.         adjcount--;
  526.         }
  527.     else break;
  528.     k++;
  529.     }
  530. j = adjcount;
  531. k = adjoff + adjcount - 1;
  532. for (i = 0; i < j; i++) {
  533.     if ((chrbuff[k] == 0x40) || (chrbuff[k] == 0x00)) adjcount--;
  534.     else break;
  535.     k--;
  536.     }
  537. (*offset) = adjoff;
  538. (*count) = adjcount;
  539. }
  540.  
  541. getdspatr(atr_result, trim_result, color_result, cattr, fattr)
  542. unsigned char * atr_result;
  543. unsigned char * trim_result;
  544. RGBColor * color_result;
  545. register unsigned short cattr;
  546. register unsigned short fattr;
  547. {
  548. register unsigned char attrbits;
  549. unsigned char exthi, color, trim, cnum;
  550. static RGBColor * HiliteRGB = (RGBColor *)0xda0;
  551.  
  552. if (trim_result != 0) trim = (*trim_result);
  553.  
  554. /* determine extended highlighting value to use */
  555. exthi = (cattr & 0x0018) >> 3;
  556. if (exthi == 0) exthi = (fattr & 0x0018) >> 3;
  557.  
  558. /* get default, highlight, or non-display attribute */
  559. switch ((fattr & 0x0C00) >> 10) {
  560.     case 0:
  561.     case 1: attrbits = cs.attrmap[0];
  562.             break;
  563.     case 2: attrbits = cs.attrmap[1];
  564.             break;
  565.     case 3: attrbits = cs.attrmap[2];
  566.             exthi = 0;    /* non-display cancels ext. high */
  567.             trim = 0;
  568.             break;
  569.     default: attrbits = 0;
  570.             break;
  571.     }
  572.     
  573. /* add extended highlighting to basic attributes */
  574. switch (exthi) {
  575.     case 0: break;
  576.     case 1: attrbits |= cs.attrmap[4];
  577.             break;
  578.     case 2: attrbits |= cs.attrmap[3];
  579.             trim = 0;
  580.             break;
  581.     case 3: attrbits |= cs.attrmap[5];
  582.             trim = 0;
  583.             break;
  584.     default: break;
  585.     }
  586.  
  587. /* adjust attrbits for mouse selection field */
  588. if (cattr & 0x0020) {
  589.     attrbits &= 0x8f;        /* cancel frame, reverse, underline */
  590.     attrbits |= 0x20;        /* set reverse bit */
  591.     trim = 0;                /* don't trim */
  592.     }
  593.  
  594. /* determine color value to use */
  595. if (colormac) {
  596.     if (cattr & 0x0020) {    /* use highlight color for selection text */
  597.         (*color_result) = (*HiliteRGB);
  598.         if ((((*color_result) == realblack) && (!cs.invertbw)) ||
  599.             (((*color_result) != realblack) && cs.invertbw)) {
  600.             (*color_result).red = 0xffff - (*color_result).red;
  601.             (*color_result).green = 0xffff - (*color_result).green;
  602.             (*color_result).blue = 0xffff - (*color_result).blue;
  603.             }
  604.         }
  605.     else {
  606.         color = cattr & 0x0007;
  607.         if (color == 0) color = fattr & 0x0007;
  608.         if (color == 0) {
  609.              if (fattr & 0x2000) {    /* protected */
  610.                 if ((fattr & 0x0c00) == 0x0800) {    /* high-intensity */
  611.                     color = 7;                                     /* white */
  612.                     }
  613.                 else {
  614.                     if (cs.basecolor || colorfield) color = 4;    /* green */
  615.                     else color = 1;                                /* blue */
  616.                     }
  617.                 }    
  618.              else {                    /* unprotected */
  619.                 if ((fattr & 0x0c00) == 0x0800) {    /* high-intensity */
  620.                     if (cs.basecolor || colorfield) color = 7;    /* white */
  621.                     else color = 2;                                /* red */
  622.                     }
  623.                 else {
  624.                     color = 4;                                    /* green */
  625.                     }
  626.                 }
  627.             }
  628.         switch(color) {
  629.             case 1:    cnum = RGBblue;
  630.                     break;
  631.             case 2:    cnum = RGBred;
  632.                     break;
  633.             case 3: cnum = RGBpink;
  634.                     break;
  635.             case 5:    cnum = RGBturquoise;
  636.                     break;
  637.             case 6:    cnum = RGByellow;
  638.                     break;
  639.             case 7:    if (cs.invertbw) cnum = RGBblack;
  640.                     else cnum = RGBwhite;
  641.                     break;
  642.             default: cnum = RGBgreen;
  643.                     break;
  644.             }
  645.         GetEntryColor(myPalette, cnum, color_result);
  646.         }
  647.     }
  648. if (trim_result != 0) (*trim_result) = trim;
  649. (*atr_result) = attrbits;
  650. }
  651.  
  652.  
  653. txtfield(offset, count, attrbits, prot, fieldfont)
  654. short offset, count;
  655. unsigned char attrbits;
  656. char prot, fieldfont;
  657. {
  658. register short start, len, lim, f, i, fnum;
  659. register unsigned char font;
  660.  
  661. start = offset;
  662. len = 0;
  663. lim = offset + count;
  664. if (atrbuff[offset] & 0x4000) {
  665.     font = 1;
  666.     }
  667. else {
  668.     font = (atrbuff[offset] & 0x00c0) >> 6;
  669.     }
  670. if (font == 0) font = fieldfont;
  671. for (i=offset; i < lim; i++) {
  672.     if (atrbuff[i] & 0x4000) {
  673.         f = 1;
  674.         }
  675.     else {
  676.         f = (atrbuff[i] & 0x00c0) >> 6;
  677.         }
  678.     if (f == 0) f = fieldfont;
  679.     if (font == f) len++;
  680.     else {
  681.         if (font == 1) fnum = APLFONT;
  682.             else fnum = stdfont;
  683.         if (attrbits & 0x08) fnum += 2;
  684.         TextFont(fnum);
  685.         myDrawText(chrbuff, start, len, fnum, prot);
  686.         font = f;
  687.         start = i;
  688.         len = 1;
  689.         }
  690.     }
  691. if (font == 1) fnum = APLFONT;
  692.     else fnum = stdfont;
  693. if (attrbits & 0x08) fnum += 2;
  694. TextFont(fnum);
  695. myDrawText(chrbuff, start, len, fnum, prot);
  696. if (fnum != stdfont) TextFont(stdfont);
  697. }
  698.  
  699. myDrawText(textBuf, firstByte, byteCount, font, prot)
  700. register unsigned char *textBuf;
  701. register short firstByte, byteCount;
  702. short font;
  703. char prot;
  704. {
  705. register short i, j;
  706.  
  707. if (byteCount <= 0) return;
  708.  
  709. if (nl_handle == 0) {    /* no translation */
  710.     if (((font == ALAFONT) || (font == BOLDALA)) && prot && (!plainala)) {
  711.         ALADrawText(textBuf, firstByte, byteCount);
  712.         }
  713.     else {
  714.         DrawText(textBuf, firstByte, byteCount);
  715.         }
  716.     return;
  717.     }
  718.  
  719. if ((font == stdfont) || (font == (stdfont+2))) {
  720.     j = firstByte;
  721.     for (i=0; i < byteCount; i++) {
  722.         nlbuff[i] = nltab[textBuf[j++]];
  723.         }
  724.     DrawText(nlbuff, 0, byteCount);
  725.     }
  726. else { /* translation does not apply to APL */
  727.     DrawText(textBuf, firstByte, byteCount);
  728.     }
  729. }
  730.  
  731. ALADrawText(textBuf, firstByte, byteCount)
  732. unsigned char *textBuf;
  733. short firstByte, byteCount;
  734. {
  735. register unsigned char *sptr;
  736. register short i, textlen, state;
  737. unsigned char *textptr;
  738. short blankcount;
  739. short alatype();
  740.  
  741. sptr = textBuf+firstByte;
  742. blankcount = textlen = 0;
  743. textptr = sptr;
  744. state = 0;
  745. for (i=firstByte; i < firstByte+byteCount; i++) {
  746.     switch(alatype(sptr)) {
  747.         case 0:                /* normal character */
  748.                 switch (state) {
  749.                     case 0:            /* normal */
  750.                             textlen++;
  751.                             break;
  752.                     case 1:            /* last char. diacritic */
  753.                             if (textlen > 1) {
  754.                                 DrawText(textptr, 0, textlen-1);
  755.                                 textptr += textlen-1;
  756.                                 }
  757.                             drawdc(*textptr, *sptr);
  758.                             movechr(-1);
  759.                             blankcount++;
  760.                             textptr = sptr;
  761.                             textlen = 1;
  762.                             state = 0;
  763.                             break;
  764.                     default:
  765.                             break;
  766.                     }
  767.                 break;
  768.         case 1:                /* blank */
  769.                 switch (state) {
  770.                     case 0:            /* pending blanks */
  771.                             if (blankcount == 0) {
  772.                                 textlen++;
  773.                                 }
  774.                             else {
  775.                                 DrawText(textptr, 0, textlen);
  776.                                 blankcount++;
  777.                                 movechr(blankcount);
  778.                                 blankcount = 0;
  779.                                 textptr = sptr + 1;
  780.                                 textlen = 0;
  781.                                 state = 0;
  782.                                 }
  783.                             break;
  784.                     case 1:            /* last char. diacritic */
  785.                             if (textlen > 1) {
  786.                                 DrawText(textptr, 0, textlen-1);
  787.                                 textptr += textlen-1;
  788.                                 }
  789.                             drawdc(*textptr, *sptr);
  790.                             blankcount++;
  791.                             textptr = sptr + 1;
  792.                             textlen = 0;
  793.                             state = 0;
  794.                             break;
  795.                     default:
  796.                             break;
  797.                     }
  798.                 break;
  799.         case 2:                /* diacritic */
  800.                 switch (state) {
  801.                     case 0:            /* normal */
  802.                     case 1:            /* last char. diacritic */
  803.                             textlen++;
  804.                             state = 1;
  805.                             break;
  806.                     default:
  807.                             break;
  808.                     }
  809.                 break;
  810.         default:
  811.                 break;
  812.         }
  813.     sptr++;
  814.     }
  815.     if (textlen > 0) {
  816.         DrawText(textptr, 0, textlen);
  817.         }
  818.     if (blankcount > 0) {
  819.         movechr(blankcount);
  820.         }
  821. }
  822.  
  823. short alatype(s)
  824. unsigned char *s;
  825. {
  826. register unsigned char c;
  827.  
  828. c = *s;
  829. if ((c == 0x40) || (c == 0x00)) return(1);        /* blank or null */
  830. if ((c%16) < 10) return(0);                        /* normal character */
  831. if (c < 0x80) return(0);
  832. if ((c >= 0xa0) && (c <= 0xbf)) return(0);
  833. if (c >= 0xf0) return(0);
  834. return(2);
  835. }
  836.  
  837. movechr(n)
  838. short n;
  839. {
  840. FontInfo fi;
  841.  
  842. if (n == 0) return;
  843. GetFontInfo(&fi);
  844. Move(fi.widMax*n, 0);
  845. }
  846.  
  847. drawdc(dc, c)            /* draw diacritic, adjusting postion depending on
  848.                            the character being modified */
  849. register unsigned char dc;
  850. register unsigned char c;
  851. {
  852. register char adjflag;
  853. FontInfo fi;
  854.  
  855. adjflag = 0;
  856.                     /* check for lowercase character */
  857. if (c == 0x40) adjflag = 1;
  858. else if ((c >= 0x52) && (c <= 0x58)) adjflag = 1;
  859. else if ((c >= 0x81) && (c <= 0x85)) adjflag = 1;
  860. else if ((c >= 0x87) && (c <= 0x88)) adjflag = 1;
  861. else if ((c >= 0x94) && (c <= 0x99)) adjflag = 1;
  862. else if (c == 0xa2) adjflag = 1;
  863. else if ((c >= 0xa4) && (c <= 0xa9)) adjflag = 1;
  864. if (adjflag) {        /* check for upper diacritic */
  865.     if ((dc >= 0x8e) && (dc <= 0x8f)) adjflag = 0;
  866.     else if ((dc >= 0x9e) && (dc <= 0x9f)) adjflag = 0;
  867.     else if ((dc >= 0xca) && (dc <= 0xcc)) adjflag = 0;
  868.     else if (dc == 0xda) adjflag = 0;
  869.     else if ((dc >= 0xdc) && (dc <= 0xdd)) adjflag = 0;
  870.     else if (dc == 0xea) adjflag = 0;
  871.     else if (dc >= 0xec) adjflag = 0;
  872.     }
  873. if (adjflag) {
  874.     GetFontInfo(&fi);
  875.     Move(0, fi.ascent/6);    /* 1 for 9 pt., 2 for 12 pt. */
  876.     }
  877. DrawChar(dc);
  878. if (adjflag) Move(0, -(fi.ascent/6));
  879. }
  880.  
  881. statline()
  882. {
  883.  
  884.     static char *days[] = {"Sun",
  885.                     "Mon",
  886.                     "Tue",
  887.                     "Wed",
  888.                     "Thu",
  889.                     "Fri",
  890.                     "Sat"
  891.                     };
  892.     static char *months[] = {"Jan",
  893.                     "Feb",
  894.                     "Mar",
  895.                     "Apr",
  896.                     "May",
  897.                     "Jun",
  898.                     "Jul",
  899.                     "Aug",
  900.                     "Sep",
  901.                     "Oct",
  902.                     "Nov",
  903.                     "Dec"
  904.                     };
  905.     struct DateRec {
  906.         short year;
  907.         short month;
  908.         short day;
  909.         short hour;
  910.         short minute;
  911.         short second;
  912.         short DayOfWeek;
  913.         } today ;
  914.  
  915.     static char result[24] = "";
  916.     static unsigned long * Ticks = (unsigned long *)0x16a;
  917.     static unsigned long last_t = 0;
  918.     static char last_stat_time = 99;
  919.     unsigned long t;
  920.     char errmsg[16];
  921.     char cpos;
  922.     char klock, kcode;
  923.     short vpos;
  924.     RGBColor rgbtemp;
  925.  
  926.     if ((((*Ticks) - last_t) > 540) || (last_stat_time != cs.stat_time)) {
  927.         if (cs.stat_time >= 8) cs.stat_time -= 8;
  928.         last_stat_time = cs.stat_time;
  929.         if (cs.stat_time > 0) {
  930.             GetTime(&today);
  931.             if (cs.stat_time == 1) {
  932.                 if (today.hour == 0) today.hour = 12;
  933.                 if (today.hour > 12) today.hour -= 12;
  934.                 }
  935.             sprintf(result,"%s %02d %s %02d:%02d",
  936.                 days[today.DayOfWeek-1],today.day,months[today.month-1],
  937.                 today.hour,today.minute);
  938.             }
  939.         else strcpy(result, "");
  940.         }
  941.  
  942.     if (colormac && drawpict) {
  943.         GetEntryColor(myPalette, RGBback, &rgbtemp);
  944.         RGBBackColor(&rgbtemp);
  945.         }
  946.     EraseRect(&statRect);
  947.     TextFont(SYMBOLFONT);
  948.     TextSize(12);
  949.     if (colormac) {
  950.         GetEntryColor(myPalette, RGBstat, &rgbtemp);
  951.         RGBForeColor(&rgbtemp);
  952.         }
  953.     cpos = cs.curpos;
  954.     klock = kblock;
  955.     kcode = kblcode;
  956.     vpos = vpixsize - 12;
  957.     if (!klock) if (wr_active) {
  958.         klock = 1;
  959.         kcode = 2;
  960.         }
  961.     if (serflg) {
  962.         if (!connflg) {
  963.             MoveTo(-2, vpos);
  964.             DrawChar(0x00);
  965.             }
  966.         }
  967.     else if (tcpflg) {
  968.         if (logon) {
  969.             MoveTo(-2, vpos);
  970.             DrawChar(0x00);
  971.             }
  972.         }
  973.     else {
  974.         if (netconn) {
  975.             MoveTo(-2, vpos);
  976.             DrawChar(0x00);
  977.             }
  978.         }
  979.     if (online) {
  980.         MoveTo(7, vpos);
  981.         DrawChar(0x01);
  982.         }
  983.     MoveTo(16, vpos);
  984.     DrawChar(0x02);
  985.     if (insmode) {
  986.         MoveTo(290, vpos);
  987.         DrawChar(0x07);
  988.         }
  989.     if (klock || (vmxbgn && (!vmxsub))) {
  990.         MoveTo(61, vpos);
  991.         DrawChar(0x03);
  992.         }
  993.     if (klock && (kcode == 2)) {
  994.         MoveTo(74, vpos);
  995.         DrawChar(0x08);
  996.         }
  997.     if (klock && (kcode == 3)) {
  998.         MoveTo(74, vpos);
  999.         DrawChar(0x09);
  1000.         DrawChar(0x0a);
  1001.         DrawChar(0x0b);
  1002.         DrawChar(0x0c);
  1003.         }
  1004.     if ((!klock) && (kb_err == 1)) {
  1005.         MoveTo(74, vpos);
  1006.         DrawChar(0x05);
  1007.         }
  1008.     if ((!klock) && (kb_err == 2)) {
  1009.         MoveTo(74, vpos);
  1010.         DrawChar(0x04);
  1011.         DrawChar(0x05);
  1012.         DrawChar(0x06);
  1013.         }
  1014.     if (ioerror != 0) {
  1015.         MoveTo(150, vpos);
  1016.         DrawChar(0x09);
  1017.         DrawChar(0x0a);
  1018.         DrawChar(0x0b);
  1019.         DrawChar(0x0c);
  1020.         MoveTo(175, vpos+1);
  1021.         DrawChar(0x01);
  1022.         }
  1023.     if (vmxbgn || ftpcopen || ftpdopen || ftplopen) {
  1024.         cpos = 0;
  1025.         MoveTo(315, vpos);
  1026.         DrawChar(0x0e);
  1027.         Move(-2, 0);
  1028.         DrawChar(0x04);
  1029.         DrawChar(0x06);
  1030.         Move(-2, 0);
  1031.         DrawChar(0x0e);
  1032.         }
  1033.     if (klock && (kcode == 4)) {
  1034.         TextFont(0);
  1035.         TextSize(0);
  1036.         MoveTo(74, vpos+1);
  1037.         DrawString("Session");
  1038.         }
  1039.     TextFont(1);
  1040.     TextSize(0);
  1041.     if (klock && (kcode == 1)) {
  1042.         MoveTo(74, vpos+1);
  1043.         DrawString("SYSTEM");
  1044.         }
  1045.     if (klock && (kcode == 3)) {
  1046.         MoveTo(112, vpos+1);
  1047.         DrawString("590");
  1048.         }
  1049.     if ((!klock) && (kb_err == 1)) {
  1050.         MoveTo(84, vpos);
  1051.         DrawChar('>');
  1052.         }
  1053.     if ((!klock) && (kb_err == 3)) {
  1054.         MoveTo(74, vpos+1);
  1055.         DrawString("?+");
  1056.         }
  1057.     if (ioerror != 0) {
  1058.         sprintf(errmsg,"%d",ioerror);
  1059.         MoveTo(188, vpos+1);
  1060.         DrawString(errmsg);
  1061.         }
  1062.     if (aplmode) {
  1063.         MoveTo(245, vpos+1);
  1064.         DrawString("APL");
  1065.         }
  1066.     if (cpos) {
  1067.         sprintf(errmsg,"%02d/%02d",y+1,x+1);
  1068.         MoveTo(cposRect.left, vpos+1);
  1069.         DrawString(errmsg);
  1070.         }
  1071.     MoveTo(hpixsize-134, vpos+1);
  1072.     DrawString(result);
  1073.     MoveTo(-4,vpixsize-25);
  1074.     LineTo(hpixsize-4,vpixsize-25);
  1075.     TextFont(stdfont);
  1076.     TextSize(cur_ptsize);
  1077.     if (colormac && drawpict) {
  1078.         if (cs.invertbw) GetEntryColor(myPalette, RGBwhite, &rgbtemp);
  1079.                  else GetEntryColor(myPalette, RGBblack, &rgbtemp);
  1080.         RGBBackColor(&rgbtemp);
  1081.         }
  1082. }
  1083.  
  1084. newstat()
  1085. {
  1086. long t;
  1087. GrafPtr gp;
  1088. BitMap * srcbits;
  1089.  
  1090. if (sw_bgrnd) {
  1091.     sw_upd = 1;
  1092.     return;
  1093.     }
  1094. if (!textmap) {                    /* no screen buffer */
  1095.     GetPort(&gp);
  1096.     SetPort(myWindow);
  1097.     statline();
  1098.     /* ValidRect(&statRect); */    /* May need new grow icon */
  1099.     SetPort(gp);
  1100.     }
  1101. else {                            /* have screen buffer */
  1102.     GetPort(&gp);
  1103.     SetPort(WritePtr);
  1104.     setgdev();
  1105.     statline();
  1106.     resetgdev();
  1107.     SetPort(myWindow);
  1108.     if (colormac) {
  1109.         RGBForeColor(&realblack);
  1110.         RGBBackColor(&realwhite);
  1111.         srcbits = (BitMap *)(*(PixMapHandle)WritePort.portBits.baseAddr);
  1112.         }
  1113.     else {
  1114.         srcbits = &WritePort.portBits;
  1115.         }
  1116.     if (statcpos) {
  1117.         CopyBits(srcbits, &(myWindow->portBits),
  1118.             &cposRect, &cposRect, srcCopy, 0L);
  1119.         }
  1120.     else {
  1121.         CopyBits(srcbits, &(myWindow->portBits),
  1122.             &statRect, &statRect, srcCopy, 0L);
  1123.         }
  1124.     /* ValidRect(&statRect); */    /* may need new grow icon */
  1125.     SetPort(gp);
  1126.     }
  1127. }
  1128.  
  1129. beep()
  1130. {
  1131. static short duration = 3;
  1132. static short sw_dur = 2;
  1133. OSErr rc;
  1134. OSErr mybeep();
  1135.  
  1136. if (apiopen) {
  1137.     if (apiopenreq.hide) return;
  1138.     }
  1139.  
  1140. if (sw_bgrnd) sw_beep = 1;
  1141.  
  1142. rc = mybeep();
  1143. if (rc == 0) return;
  1144.     
  1145. if (sw_bgrnd || mf_bgrnd) {
  1146.     SysBeep(sw_dur);
  1147.     SysBeep(sw_dur);
  1148.     }
  1149. else SysBeep(duration);
  1150. }
  1151.  
  1152. OSErr mybeep()
  1153. {
  1154. OSErr rc, playrc;
  1155. SndChannelPtr default_scp;
  1156. extern sndproc();
  1157. SndCommand endcmd;
  1158.  
  1159. if (sndhandle == 0) return(1);
  1160.  
  1161. if (sndactive) {
  1162.     SndDisposeChannel(scp, true);
  1163.     sndactive = 0;
  1164.     }
  1165.  
  1166. if (mf_bgrnd || sw_bgrnd) {        /* play sound synchronously */
  1167.     default_scp = 0;
  1168.     rc = SndNewChannel(&default_scp, 0, 0L, 0L);
  1169.     if (rc == noErr) {
  1170.         playrc = SndPlay(default_scp, sndhandle, 0);
  1171.         rc = SndDisposeChannel(default_scp, 0);
  1172.         if (playrc == noErr) return(rc);
  1173.         else return(playrc);        
  1174.         }
  1175.     else {
  1176.         return(rc);
  1177.         }
  1178.     }
  1179.  
  1180. rc = SndNewChannel(&scp, 0, 0L, sndproc);
  1181. if (rc != noErr) return(rc);
  1182. rc = SndPlay(scp, sndhandle, true);
  1183. if (rc != noErr) {
  1184.     SndDisposeChannel(scp, true);
  1185.     return(rc);
  1186.     }
  1187. sndactive = 1;
  1188. endcmd.cmd = callBackCmd;
  1189. endcmd.param1 = 0;
  1190. endcmd.param2 = GetA5();
  1191. rc = SndDoCommand(scp, &endcmd, true);
  1192. if (rc != noErr) {
  1193.     SndDisposeChannel(scp, true);
  1194.     sndactive = 0;
  1195.     }
  1196. return(rc);
  1197. }
  1198.  
  1199. sndend()
  1200. {
  1201. if (sndactive == 1) sndactive = 2;        /* indicate dispose call needed */
  1202. }
  1203.  
  1204. drawcurs(restore)        /* draw cursor in screen window */
  1205. char restore;
  1206. {
  1207. RGBColor rgbchar, mywhite, myblack, myback;
  1208. static RGBColor rgbbk;        /* save for restore call */
  1209. unsigned short color, foffset, fattr, cattr;
  1210. unsigned char attrbits, trim;
  1211. short start, end, count, lend;
  1212. static unsigned char * hiliteMode = (unsigned char *)0x938;
  1213.  
  1214. if (!colormac) {        /* just invert rectangle if no color */
  1215.     InvertRect(&er);
  1216.     return;
  1217.     }
  1218.  
  1219.                         /* get colors we will need */
  1220. GetEntryColor(myPalette, RGBwhite, &mywhite);
  1221. GetEntryColor(myPalette, RGBblack, &myblack);
  1222. GetEntryColor(myPalette, RGBback, &myback);
  1223.  
  1224. if (!restore) {            /* compute background if not restore call */
  1225.                                     /* define attrbits and trim */
  1226.     foffset = getattr(curadr);
  1227.     fattr = atrbuff[foffset];
  1228.     cattr = atrbuff[curadr];
  1229.     trim = 1;
  1230.     getdspatr(&attrbits, &trim, &rgbchar, cattr, fattr);
  1231.     if (!(fattr & 0x2000)) trim = 0;    /* unprotected not trimmed */
  1232.     if (cattr & 0x8000) {                /* handle attribute byte */
  1233.         attrbits = cs.attrmap[6];
  1234.         trim = 0;
  1235.         }
  1236.                                     /* determine background color */
  1237.                                         /* reversed or underline cursor & field */
  1238.     if ((attrbits & 0x20) || ((attrbits & 0x10) && (!cs.blockcurs))) {
  1239.         if (trim) {
  1240.             start = (curadr/scrhsize) * scrhsize;
  1241.             lend = start + scrhoff;
  1242.             if ((foffset >= start) && (foffset < curadr))
  1243.                 start = foffset+1;
  1244.             end = start;
  1245.             while (end < lend) {
  1246.                 end++;
  1247.                 if (atrbuff[end] & 0x8000) {
  1248.                     end--;
  1249.                     break;
  1250.                     }
  1251.                 }
  1252.             count = end - start + 1;
  1253.             calctrim(&start, &count);
  1254.             end = start + count - 1;
  1255.             if ((count > 0) && (curadr >= start) && (curadr <= end)) trim = 0;
  1256.             }
  1257.         if (trim) rgbbk = myback;    /* trim actually applies where cursor is */
  1258.         else if (((attrbits & 0x30) == 0x30) && (!cs.blockcurs)) {
  1259.                                         /* reverse & underline & underline cursor */
  1260.                     if (cs.invertbw) rgbbk = mywhite;
  1261.                     else rgbbk = myblack;
  1262.                     }
  1263.              else rgbbk = rgbchar;        /* reverse | underline & underline cursor */
  1264.         }
  1265.     else rgbbk = myback;                /* normal */
  1266.     }
  1267.                             /* hilight (or unhilight) cursor rectangle */
  1268. if (cs.invertbw) {
  1269.     HiliteColor(&myblack);
  1270.     RGBBackColor(&rgbbk);
  1271.     }
  1272. else {
  1273.     RGBBackColor(&mywhite);
  1274.     HiliteColor(&rgbbk);
  1275.     }
  1276. (*hiliteMode) &= 0x7f;
  1277. InvertRect(&er);
  1278.                             /* restore what we changed */
  1279. HiliteColor(&realblack);
  1280. if (textmap) RGBBackColor(&realwhite);
  1281. else RGBBackColor(&myback);
  1282. }
  1283.  
  1284. defcursor(cx, cy)
  1285. short cx, cy;
  1286. {
  1287. er.left = cx * htxtsize;
  1288. er.top = cy * vtxtsize;
  1289. er.right = er.left + curhsize;
  1290. er.bottom = er.top + curvsize;
  1291. if (cs.blockcurs) return;
  1292. er.bottom -= (curvsize>>2) - 1;
  1293. er.top = er.bottom - 1;
  1294. }
  1295.  
  1296. justGrowIcon(rgnok)
  1297. char rgnok;
  1298. {
  1299. GrafPtr psave;
  1300. RGBColor myback, mystat, actback, actstat;
  1301. Rect temprect;
  1302.  
  1303. GetPort(&psave);
  1304. SetPort(myWindow);
  1305. if (!rgnok) SetClip(cliprgn);
  1306.  
  1307. if (colormac) {
  1308.     GetEntryColor(myPalette, RGBback, &myback);
  1309.     GetEntryColor(myPalette, RGBstat, &mystat);
  1310.     actualcolor(&myback, &actback);
  1311.     actualcolor(&mystat, &actstat);
  1312.     if (actback == actstat) InvertColor(&mystat);
  1313.     RGBForeColor(&mystat);
  1314.     if (textmap) RGBBackColor(&myback);
  1315.     }
  1316.  
  1317. temprect = myWindow->portRect;
  1318. temprect.top = temprect.bottom-15;
  1319. temprect.left = temprect.right-15;
  1320. EraseRect(&temprect);
  1321. MoveTo(temprect.left, temprect.bottom);
  1322. LineTo(temprect.left, temprect.top);
  1323. LineTo(temprect.right, temprect.top);
  1324. if (((WindowPeek)myWindow)->hilited) {
  1325.     temprect.left += 3;
  1326.     temprect.right = temprect.left + 7;
  1327.     temprect.top += 3;
  1328.     temprect.bottom = temprect.top + 7;
  1329.     FrameRect(&temprect);
  1330.     MoveTo(temprect.right, temprect.bottom-5);
  1331.     Line(3, 0);
  1332.     Line(0, 8);
  1333.     Line(-8, 0);
  1334.     Line(0, -3);
  1335.     }
  1336. if (colormac && textmap) RGBBackColor(&realwhite);
  1337.  
  1338. if (!rgnok) SetClip(destrgn);
  1339.  
  1340. SetPort(psave);
  1341. }
  1342.  
  1343. xfGrowIcon()
  1344. {
  1345. GrafPtr psave;
  1346. Rect temprect;
  1347.  
  1348. GetPort(&psave);
  1349. SetPort(xdlgptr);
  1350.  
  1351. temprect = xdlgptr->portRect;
  1352. temprect.top = temprect.bottom-15;
  1353. temprect.left = temprect.right-15;
  1354. EraseRect(&temprect);
  1355. MoveTo(temprect.left, temprect.bottom);
  1356. LineTo(temprect.left, temprect.top);
  1357. LineTo(temprect.right, temprect.top);
  1358. if (((WindowPeek)xdlgptr)->hilited) {
  1359.     temprect.left += 3;
  1360.     temprect.right = temprect.left + 7;
  1361.     temprect.top += 3;
  1362.     temprect.bottom = temprect.top + 7;
  1363.     FrameRect(&temprect);
  1364.     MoveTo(temprect.right, temprect.bottom-5);
  1365.     Line(3, 0);
  1366.     Line(0, 8);
  1367.     Line(-8, 0);
  1368.     Line(0, -3);
  1369.     }
  1370. SetPort(psave);
  1371. }
  1372.  
  1373. InitClip()
  1374. {
  1375. ClipRect(&(myWindow->portRect));
  1376. GetClip(cliprgn);
  1377. gr_rect = myWindow->portRect;
  1378. gr_rect.top = gr_rect.bottom-15;
  1379. gr_rect.left = gr_rect.right-15;
  1380. RectRgn(temprgn, &gr_rect);
  1381. DiffRgn(cliprgn, temprgn, destrgn);
  1382. SetClip(destrgn);
  1383. }
  1384.  
  1385. mousesel(function, location, doubleflag)
  1386. short function, location;
  1387. char doubleflag;
  1388. {
  1389. static short init_loc;
  1390. static char showsel;
  1391. static short sel_loc;
  1392. short toploc, bottomloc;
  1393. short startcol, toprow, endcol, bottomrow, t;
  1394. short scrtop, scrbottom, scrtop2, scrbottom2;
  1395. short scrstart, scrend, scrleft, scrright;
  1396.  
  1397. switch(function) {
  1398.     case 0:                    /* initialization */
  1399.                 init_loc = location;
  1400.                 showsel = 0;
  1401.                 break;
  1402.     case 1:                    /* display call */
  1403.     case 2:
  1404.                 if (location != init_loc) {
  1405.                     if (showsel) {
  1406.                         if (location == sel_loc) break;
  1407.                         invsel(&lastsel);
  1408.                         }
  1409.                         /* define lastsel */
  1410.                     toploc = init_loc;
  1411.                     bottomloc = location;
  1412.                     if (toploc > bottomloc) {
  1413.                         toploc = location;
  1414.                         bottomloc = init_loc;
  1415.                         }
  1416.                     if (function == 2) {
  1417.                         bottomloc--;
  1418.                         if (doubleflag) wordadj(&toploc, &bottomloc, 0);
  1419.                         }
  1420.                     startcol = toploc % scrhsize;
  1421.                     endcol = bottomloc % scrhsize;
  1422.                     toprow = toploc / scrhsize;
  1423.                     bottomrow = bottomloc / scrhsize;
  1424.                     if ((function == 1) && (startcol > endcol)) {
  1425.                         t = startcol;
  1426.                         startcol = endcol;
  1427.                         endcol = t;
  1428.                         }
  1429.                     scrtop = toprow * vtxtsize + htxtstrt - 1;
  1430.                     scrbottom2 = bottomrow * vtxtsize + htxtstrt - 1;
  1431.                     scrtop2 = (toprow+1) * vtxtsize + htxtstrt -1;
  1432.                     scrbottom  = (bottomrow+1) * vtxtsize + htxtstrt -1;
  1433.                     scrstart = startcol * htxtsize;
  1434.                     scrleft = 0;
  1435.                     scrend = (endcol+1) * htxtsize + 1;
  1436.                     scrright = scrhsize * htxtsize + 1;
  1437.                     if ((function == 1) ||
  1438.                         ((startcol == 0) && (endcol == scrhoff)) ||
  1439.                         (toprow == bottomrow)) {
  1440.                         lastsel.x1 = lastsel.x2 = lastsel.x3 = lastsel.x8 =
  1441.                             scrstart;
  1442.                         lastsel.x4 = lastsel.x5 = lastsel.x6 = lastsel.x7 =
  1443.                             scrend;
  1444.                         lastsel.y1 = lastsel.y2 = lastsel.y3 = lastsel.y4 =
  1445.                             scrtop;
  1446.                         lastsel.y5 = lastsel.y6 = lastsel.y7 = lastsel.y8 =
  1447.                             scrbottom;
  1448.                         }
  1449.                     else {
  1450.                         lastsel.x1 = scrleft;
  1451.                         lastsel.y1 = scrtop2;
  1452.                         lastsel.x2 = scrstart;
  1453.                         lastsel.y2 = scrtop2;
  1454.                         lastsel.x3 = scrstart;
  1455.                         lastsel.y3 = scrtop;
  1456.                         lastsel.x4 = scrright;
  1457.                         lastsel.y4 = scrtop;
  1458.                         lastsel.x5 = scrright;
  1459.                         lastsel.y5 = scrbottom2;
  1460.                         lastsel.x6 = scrend;
  1461.                         lastsel.y6 = scrbottom2;
  1462.                         lastsel.x7 = scrend;
  1463.                         lastsel.y7 = scrbottom;
  1464.                         lastsel.x8 = scrleft;
  1465.                         lastsel.y8 = scrbottom;
  1466.                         if (startcol == 0) {
  1467.                             lastsel.x2 = lastsel.x3 = lastsel.x1;
  1468.                             lastsel.y1 = lastsel.y2 = lastsel.y3;
  1469.                             }
  1470.                         if (endcol == scrhoff) {
  1471.                             lastsel.x6 = lastsel.x7 = lastsel.x5;
  1472.                             lastsel.y5 = lastsel.y6 = lastsel.y7;
  1473.                             }
  1474.                         }
  1475.                     invsel(&lastsel);
  1476.                     showsel = 1;
  1477.                     sel_loc = location;
  1478.                     break;
  1479.                     }            
  1480.                 if (showsel == 0) break;
  1481.                 invsel(&lastsel);
  1482.                 showsel = 0;
  1483.                 break;
  1484.     case 3:                    /* termination */
  1485.                 if (showsel == 0) break;
  1486.                 invsel(&lastsel);
  1487.                 showsel = 0;
  1488.                 break;
  1489.     default:
  1490.                 break;
  1491.     }    
  1492. }
  1493.  
  1494. invsel(r)
  1495. selcoord * r;
  1496. {
  1497. PenState ps;
  1498. GrafPtr gp;
  1499. static Pattern gray =
  1500.     {0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55};
  1501. selcoord s;
  1502.  
  1503. s = *r;
  1504. GetPort(&gp);
  1505. SetPort(myWindow);
  1506. GetPenState(&ps);
  1507. PenPat(gray);
  1508. PenMode(patXor);
  1509. MoveTo(s.x1, s.y1);
  1510. if ((s.x2 != s.x1) || (s.y2 != s.y1)) {
  1511.     if ((s.y1 == s.y6) && (s.x6 < s.x2)) {
  1512.         LineTo(s.x6, s.y6);
  1513.         MoveTo(s.x2, s.y2);
  1514.         }
  1515.     else LineTo(s.x2, s.y2);
  1516.     }
  1517. if ((s.x3 != s.x2) || (s.y3 != s.y2)) LineTo(s.x3, s.y3);
  1518. LineTo(s.x4, s.y4);
  1519. LineTo(s.x5, s.y5);
  1520. if ((s.x6 != s.x5) || (s.y6 != s.y5)) {
  1521.     if ((s.y1 == s.y6) && (s.x6 < s.x2)) {
  1522.         LineTo(s.x2, s.y2);
  1523.         MoveTo(s.x6, s.y6);
  1524.         }
  1525.     else LineTo(s.x6, s.y6);
  1526.     }
  1527. if ((s.x7 != s.x6) || (s.y7 != s.y6)) LineTo(s.x7, s.y7);
  1528. LineTo(s.x8, s.y8);
  1529. LineTo(s.x1, s.y1);
  1530. SetPenState(&ps);
  1531. SetPort(gp);
  1532. }